package org.example.repository.dialect.mysql;

import lombok.extern.slf4j.Slf4j;
import org.example.repository.Schema;
import org.example.repository.SchemaSynchronizer;
import org.springframework.jdbc.core.JdbcTemplate;

@Slf4j
public class MysqlSchemaSynchronizer implements SchemaSynchronizer {

    private final JdbcTemplate jdbcTemplate;

    public MysqlSchemaSynchronizer(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public void sync(Schema schema) {
        SqlStatement result = new SqlBuilder(schema).buildCreateTableStatement();
        String sql = result.sql;
        log.info("sql: {}", sql);
        jdbcTemplate.execute(sql);
    }
}
